package num11;

public class Leecode141 {
    public class ListNode{
        public int val;
        public ListNode next;
        ListNode(){

        }
      ListNode(int val){
            this.val = val;

      }
    }
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode fast = head.next;
        ListNode slow = head;
        while (fast != slow) {
            if (fast == null || fast.next == null) {
                return false;
            }
            slow = slow.next;
            fast = fast.next.next;


        }
        return true;
    }





}
